/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.ruchin.tek.employees.web;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import ru.ruchin.tek.employees.data.Department;
import ru.ruchin.tek.employees.data.Employee;
import ru.ruchin.tek.employees.data.EmployeeStorage;

/**
 *
 * @author yruchin
 */
public class FillDatabaseHandler implements QueryHandler {
    @Override
    public String handleQuery(Map<String, String[]> query, ServletContext context) {
        List<Department> departments = new LinkedList<Department>();

        Department d = Department.createDepartment("NIM");
        Employee e = new Employee();
        e.setFirstName("Yury");
        e.setLastName("Ruchin");
        e.setEmail("yruchin@mera.ru");
        d.addEmployee(e);
        departments.add(d);

        d = Department.createDepartment("Tektronix");
        e = new Employee();
        e.setFirstName("Albert");
        e.setLastName("Avanesov");
        d.addEmployee(e);
        departments.add(d);

        d = Department.createDepartment("Tieto");
        e = new Employee();
        e.setFirstName("Alexey");
        e.setLastName("Tsaregorodtsev");
        d.addEmployee(e);
        departments.add(d);

        d = Department.createDepartment("Nortel");
        e = new Employee();
        e.setFirstName("Andrey");
        e.setLastName("Konakov");
        d.addEmployee(e);

        e = new Employee();
        e.setFirstName("Andrey");
        e.setLastName("Nekonakov");
        d.addEmployee(e);
        departments.add(d);
        EmployeeStorage es = (EmployeeStorage)context.getAttribute(EmployeeStorage.CONTEXT_KEY);
        es.saveDepartments(departments);

        return "";
    }
}
